/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import DAO.EnderecoDAO;
import DAO.RecursoDAO;
import DAO.TipoEspacoDAO;
import Model.Endereco;
import Model.Recurso;
import Model.TipoEspaco;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;

/**
 *
 * @author Maury
 */
public class preparaCadastroEspaco extends Processor {

    @Override
    public void execute() throws ServletException, IOException {
        try {
            ArrayList<Endereco> enderecos = EnderecoDAO.pesquisarAll();
            ArrayList<TipoEspaco> tipos = TipoEspacoDAO.pesquisarAll();
            ArrayList<Recurso> recursos = RecursoDAO.pesquisarAll();
            
            if(enderecos == null || tipos == null || recursos == null){
                String mensagem = "Erro no sistema!";
                getRequest().setAttribute("mensagem", mensagem);
                RequestDispatcher rd = getRequest().getRequestDispatcher("menuAdministrador.jsp");
                rd.forward(getRequest(), getResponse());
            }
            else{
                getRequest().setAttribute("enderecos", enderecos);
                getRequest().setAttribute("tipos", tipos);
                getRequest().setAttribute("recursos", recursos);
                RequestDispatcher rd = getRequest().getRequestDispatcher("cadastrarEspaco.jsp");
                rd.forward(getRequest(), getResponse());
            }
        } catch (SQLException ex) {
            throw new ServletException(ex);
        } catch (ClassNotFoundException ex) {
            throw new ServletException(ex);
        }     
        
    }
    
}
